<?php
/**
 * Pertyler
 * Moderator Page
 *
 * @author	Emre Hasegeli <hasegeli@gmail.com>
 * @license	GNU General Public License v3
 */

namespace Pertyler;

require 'main.php';

$moderator = Pertyler_Role_Moderator::Select();

$tree = $page->Tree($moderator);

if($tree->Pressed() == 'okay')
	if($_POST['NewPassword'] == $_POST['NewPasswordAgain'])
		if($moderator->UpdatePassword($_POST['Password'], $_POST['NewPassword']))
			$tree->AddProperty('Changed');

if($tree->Pressed() == 'changePassword')
{
	$tree->AddButton('okay');

	$tree->AddButton('cancel');

	$tree->Add(new TreeLeaf('Old Password', '<input type="password" name="Password" maxlength="20">'));

	$tree->Add(new TreeLeaf('New Password', '<input type="password" name="NewPassword" maxlength="20">'));

	$tree->Add(new TreeLeaf('New Password', '<input type="password" name="NewPasswordAgain" maxlength="20">'));
}
else
	$tree->AddButton('changePassword');

echo $tree;